#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int dp[N][N];

int n,m;
int lose[N],win[N],val[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&lose[i],&win[i],&val[i]);
	}
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		for(int j=m;j>=0;j--){
			int v1=dp[i-1][j]+lose[i];
			int v2;
			if(val[i]<=j){
				v2=dp[i-1][j-val[i]]+win[i];
			}
			else v2=v1;
			dp[i][j]=max(v1,v2);
		}
	}
	printf("%lld",5L*dp[n][m]);
	return 0;
}
